/*
 * Copyright (C) 2012  E-dance Studio Harbin Institute of Technology 
 * Project:campusmobile
 * Author: 初楷博
 * Create Date: 2012-5-29下午07:23:19
 */
package hit.edance.campusmobile.chat.model;

import hit.edance.campusmobile.chat.util.PictureUtil;

import java.util.ArrayList;
import java.util.List;

import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.packet.VCard;

import android.graphics.Bitmap;

/**   
 * 用户基本信息<br/>
 * jabberId JID<br/>
 * icon<br/>
 * nickname<br/>
 * signature<br/>
 * group<br/>
 * status<br/>
 * 
 * @Project campusmobile
 * @Package hit.edance.campusmobile.chat.model
 * @Class User
 * @Date 2012-5-29 下午07:23:19
 * @author 初楷博
 * @version 1.0
 * @since 1.0
 */
public class User {
	
	/**
	  * 获取用户信息
	  */
	public static User getUserInfo(XMPPConnection connection, User user) {
		try {
			VCard vcard = new VCard();
			vcard.load(connection, user.getJabberId());
			if (vcard != null) 	
				user.setIcon(PictureUtil.getPicFromBytes(vcard.getAvatar(),null))
				.setNickname(vcard.getNickName())
				.setSignature(vcard.getEmailHome());
			if(user.getNickname() == null)
				user.setNickname(user.getJabberId());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;
	}
	
	private String jabberId;
	private Bitmap icon;
	private String nickname;
	private String signature;
	private List<RosterGroup> groups = new ArrayList<RosterGroup>();
	private String status;
	
	public User(){}

	/**
	 * @return the jabberId
	 */
	public String getJabberId() {
		return jabberId;
	}

	/**
	 * @param jabberId the jabberId to set
	 */
	public User setJabberId(String jabberId) {
		this.jabberId = jabberId;
		return this;
	}

	/**
	 * @return the icon
	 */
	public Bitmap getIcon() {
		return icon;
	}

	/**
	 * @param icon the icon to set
	 */
	public User setIcon(Bitmap icon) {
		this.icon = icon;
		return this;
	}

	/**
	 * @return the nickname
	 */
	public String getNickname() {
		return nickname;
	}

	/**
	 * @param nickname the nickname to set
	 */
	public User setNickname(String nickname) {
		this.nickname = nickname;
		return this;
	}

	/**
	 * @return the signature
	 */
	public String getSignature() {
		return signature;
	}

	/**
	 * @param signature the signature to set
	 */
	public User setSignature(String signature) {
		this.signature = signature;
		return this;
	}

	public void addGroup(RosterGroup group){
		if(group != null)
			this.groups.add(group);
	}
	

	/**
	 * @return the groups
	 */
	public List<RosterGroup> getGroups() {
		return groups;
	}

	/**
	 * @param groups the groups to set
	 */
	public User setGroups(List<RosterGroup> groups) {
		this.groups = groups;
		return this;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public User setStatus(String status) {
		this.status = status;
		return this;
	}

	/* @see java.lang.Object#toString()
	 *toString
	 */
	@Override
	public String toString() {
		return "User [jabberId=" + jabberId + ", icon=" + icon + ", nickname="
				+ nickname + ", signature=" + signature + ", groups=" + groups
				+ ", status=" + status + "]";
	}


}
